package cn.gzsxt.music.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

import cn.gzsxt.music.query.UserCollectQueryObject;

@Mapper
public interface UserCollectMapper {

	@SelectProvider(type=UserCollectProvider.class,method="getUsListTotalByQo")
	Long selectUsTotalByQo(UserCollectQueryObject qo);

	@SelectProvider(type=UserCollectProvider.class,method="selectUsListByQo")
	List<Map<String, Object>> selectUsListByQo(UserCollectQueryObject qo);

	@SelectProvider(type=UserCollectProvider.class,method="getUcListTotalByQo")
	Long selectUcTotalByQo(UserCollectQueryObject qo);

	@SelectProvider(type=UserCollectProvider.class,method="selectUcListByQo")
	List<Map<String, Object>> selectUcListByQo(UserCollectQueryObject qo);

	@SelectProvider(type=UserCollectProvider.class,method="getUsrListTotalByQo")
	Long selectUsrTotalByQo(UserCollectQueryObject qo);

	@SelectProvider(type=UserCollectProvider.class,method="selectUsrListByQo")
	List<Map<String, Object>> selectUsrListByQo(UserCollectQueryObject qo);

	@Select("select cd_id id,cd_name text from mc_cd")
	List<Map<String, Object>> getAllCds();

	@Insert("INSERT INTO mc_uclist (cd_id,ucList_date,user_id) VALUES (#{cd_id},#{ucList_date},(SELECT user_id FROM mc_user WHERE user_name = #{user_name}))")
	int insertUcList(Map<String, Object> params);

	@Update("UPDATE mc_cd SET cd_like = cd_like + 1 WHERE cd_id = #{cd_id}")
	int updateCd(Map<String, Object> params);

	@Update("UPDATE mc_uclist SET cd_id = #{cd_id},ucList_date = #{ucList_date},user_id = (SELECT user_id FROM mc_user WHERE user_name = #{user_name}) WHERE ucList_id = #{ucList_id}")
	int updateUcList(Map<String, Object> params);

	@Delete("delete from mc_ucList where ucList_id = #{ucList_id}")
	int deleteUcListById(Long ucList_id);

	@Select("select * from mc_songlist where songList_name = #{songList_name}")
	List<Map<String, Object>> getSongListByName(String songList_name);

	@Insert("INSERT INTO mc_uslist (usList_date,user_id,songList_id) VALUES (#{usList_date},(SELECT user_id FROM mc_user WHERE user_name = #{user_name}),#{songList_id})")
	int inserUsList(Map<String, Object> params);

	@Insert("insert into mc_songlist (songList_name,songList_like,user_id) values (#{songList_name},1,(SELECT user_id FROM mc_user WHERE user_name = #{user_name}))")
	@Options(useGeneratedKeys=true,keyProperty="songList_id",keyColumn="songList_id")
	int insertSongList(Map<String, Object> params);

	@Update("UPDATE mc_songlist SET songList_like = songList_like + 1 WHERE songList_id = #{songList_id}")
	int updateSongList(Map<String, Object> params);

	@Update("update mc_uslist set user_id = #{user_id},songList_id = #{songList_id},usList_date = #{usList_date} where usList_id = #{usList_id}")
	int updateUsList(Map<String, Object> params);

	@Delete("delete from mc_uslist where usList_id = #{usList_id}")
	int deleteUsListById(Long usList_id);

	@Select("select singer_id id,singer_name text from mc_singer")
	List<Map<String, Object>> getAllSingers();

	@Insert("insert into mc_usrlist (user_id,singer_id,usrList_date) values (#{user_id},#{singer_id},#{usrList_date})")
	int insertUsrList(Map<String, Object> params);

	@Update("UPDATE mc_singer SET singer_like = singer_like + 1 WHERE singer_id = #{singer_id}")
	int updateSinger(Map<String, Object> params);

	@Update("update mc_usrlist set user_id = #{user_id},singer_id = #{singer_id},usrList_date = #{usrList_date} where usrList_id = #{usrList_id}")
	int updateUsrList(Map<String, Object> params);

	@Delete("delete from mc_usrlist where usrList_id = #{usrList_id}")
	int deleteUsrListById(Long usrList_id);

	@Select("SELECT count(*) FROM mc_uslist l,mc_user u,mc_songlist s WHERE l.user_id = u.user_id AND l.songList_id = s.songList_id AND u.user_name = #{user_name} AND songList_name = #{songList_name}")
	Long checkUsByUnameAndSname(Map<String, Object> params);

	@Select("SELECT count(*) FROM mc_uclist l,mc_user u,mc_cd c WHERE l.user_id = u.user_id AND c.cd_id = l.cd_id AND u.user_name = #{user_name} AND c.cd_id = #{cd_id}")
	Long checkUcByUnameAndCid(Map<String, Object> params);

	@Select("SELECT count(*) FROM mc_usrlist l,mc_user u,mc_singer s WHERE l.user_id = u.user_id AND l.singer_id = s.singer_id AND u.user_name = #{user_name} AND s.singer_id = #{singer_id}")
	Long checkUsrByUnameAndRid(Map<String, Object> params);

}
